<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>功能栏</title>
<script language="javascript" src="../script/common.js"></script>
<script language="javascript">
	var localCache = Common.getLocalCache()
	function callMainMenu() {
		DWR.call("partyService.getRootOrg",function(result){
			if (result)
				localCache['rootOrg']=result.organization
		
		})
		
		DWR.call("partyService.findSystemState",function(result){
			$("sysVersion").innerHTML = result.version
		});

		DWR.call("loginService.getCurrentLogin",showWelcome);
		if($("skinSelect"))
			$("skinSelect").value = getCookie("userskin");
	}
	function hourToText(){
		var hour = new Date().getHours();
		if (hour<6) return "晚上";
		if (hour<9) return "早上";
		if (hour<11) return "上午";
		if (hour<14) return "中午";
		if (hour<19) return "下午";
		return "晚上";
	}
	function showWelcome(login){
		if (login){
			localCache['cOper']=login
			localCache['cOrgs'] = {}
			var html_user = hourToText()+"好，";
			html_user += "<a href='#' onclick='showOperInfo()'>"+login.name+"</a>";
			$("userInfo").innerHTML = html_user;
			var html = "当前机构 <select id=orgs>";
			for(var i=0;i<login.orgs.length;i++){
				var org = login.orgs[i];
				html += "<option value="+org.id+">"+org.name+"</option>";
				localCache['cOrgs'][org.id] = org;
			}
			html += "</select>";
			$("welcome").innerHTML = html;
			
			if (login.orgs.length>0){
			
				localCache['cOrg']=login.orgs[0]
			}
			DWR.call("loginService.findModules",null,showMainMenu);
		}else{
			return;	
			alert("系统未登录,请重新登录")
			returnToLogin();
		}
	}
	function showOperInfo(){
		parent.mainFrame.document.location.href = "../basic/operator_info.html";
	}
	function returnToLogin(){
		try{
			parent.opener.document.location.href='../login.html';
			parent.close();
		}catch(e){
			parent.close();
		}
	}
	
	function showMainMenu(result){
		var html = "";
		var firstAction = "";
		for(var i=0;i<result.length;i++){
			var id = result[i].id;
			var text = trim(result[i].name);
			var uniqueId = trim(result[i].uniqueId);
			var icon = result[i].iconUrl;
			if(icon.charAt(0) == "/"){
				icon = icon.substring(1);
				icon = appRoot + icon;
			}
			if(i != 0){
				html += "<img src='../images/frame/menudot.gif' align='absmiddle'>";
			}
			else{
				html = "<img src='../images/basic/spacer.gif' width=5 height=5 align='absmiddle'>" + html;
				firstAction = "id="+id+"&name="+esc(text)+"&uniqueId="+uniqueId;
			}
			html += " <a tabindex='-1' onfocus='this.blur()' href='../common/left.html?id="+id+"&name="+esc(text)+"&uniqueId="+uniqueId+"' onclick='showBlankPage()' target='leftFrame'><img src='"+icon+"' align='absmiddle'>"+text+"</a> ";
		}
		$("mainMenu").innerHTML = html;
		if(firstAction != ""){
			parent.leftFrame.document.location.href = "../common/left.html?" + firstAction;
			parent.mainFrame.document.location.href = "../common/blank.html?" + firstAction;
		}else{
			alert("当前操作员没有被授予任何权限")
			returnToLogin();
		}
	}
	function showBlankPage(){
		parent.mainFrame.document.location.href = "../common/blank.html";
	}
	function logout(){
		DWR.call("loginService.logout",function(){});
		returnToLogin();
	}
	function setSkin(obj){
		setCookie("userskin",obj.value);
		parent.location.reload();
	}
	/* 框架刷新方法 */
	function reloadFrames(){
		var objs = parent.parent.frames;
		var len = objs.length;
		if(len){
			for(i=1;i<objs.length;i++){
				var cLocation = objs[i].location.href;
				if(cLocation)
					objs[i].location.href = cLocation;
			}	
		}
	}
</script>

</head>
<body onload="callMainMenu()" onunload="">
<table cellSpacing=0 cellPadding=0 width="100%" border=0 height="61">
	<tr>
		<td id="bannerLeft" width=350 nowrap></td>
		<td id="bannerRight" align="right" nowrap>
					<span class="bold gray" id="userInfo"></span>。
					软件版本：<span id="sysVersion"></span>
					<!--
					，配色方案:<select id="skinSelect" onchange="setSkin(this)">
					<option value="red">红色</option>
					<option value="blue">蓝色</option>
					<option value="green">绿色</option>
					<option value="gray">灰色</option>
					</select>
					-->
		</td>
	</tr>
</table>
<table cellSpacing=0 cellPadding=0 width="100%" border=0 class="topMenuBg">
	<tr class="topBtn">
		<td id="mainMenu" nowrap></td>
		<td id="welcome" nowrap align="right" style="padding-right:20px">
		</td>
		<td width="15%" nowrap>
			<a tabindex="-1" href="javascript:void(0)" onfocus="this.blur()" onclick="reloadFrames()"><img src="../images/icon/refresh.gif" align="absmiddle" border="0">刷新</a>
			<a tabindex="-1" href="javascript:void(0)" onfocus="this.blur()" onclick="logout()"><img src="../images/icon/logout.gif" align="absmiddle" border="0">注销</a>
		</td>
	</tr>
</table>
</body>
</html>
